﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PBO.Data;

namespace PBO.Game.BattleClass
{
    public partial class Battle
    {
        public static double CalculateAttackTypeEffect(Pokemon attacker, Pokemon defencer, BattleType moveType)
        {
            double typeEff1 = CalculateTypeEffect(attacker, defencer, moveType, defencer.Type1);
            if (typeEff1 == 0)
            {
                return 0;
            }

            double typeEff2 = 1;
            if (defencer.Type2 != BattleType.None)
            {
                typeEff2 = CalculateTypeEffect(attacker, defencer, moveType, defencer.Type2);
                if (typeEff2 == 0)
                {
                    return 0;
                }
            }
            return typeEff1 * typeEff2;
        }

        /// <summary>
        /// 计算属性影响
        /// </summary>
        private static double CalculateTypeEffect(Pokemon attacker, Pokemon defencer, BattleType attackType, BattleType defenceType)
        {
            double typeEff1 = attackType.EffectRevise(defenceType);

            if (typeEff1 == 0)
            {
                BattleGround ground = attacker.MyTeam.ground;
                if ((ground.Gravity || defencer.GetItem() == Item.IronBall || defencer.BattleState.ingrain) && attackType == BattleType.Ground)
                {
                    typeEff1 = 1;
                }
                else if (defencer.BattleState.miracleEye && attackType == BattleType.Psychic)
                {
                    typeEff1 = 1;
                }
                else if ((defencer.BattleState.foresight || (attacker != null && attacker.GetSelTrait() == Trait.Scrappy)) && (attackType == BattleType.Normal || attackType == BattleType.Fighting))
                {
                    typeEff1 = 1;
                }
            }
            return typeEff1;
        }

        public static double CalculateAttackerTypeRevision(double typeEffect, BattleType moveType, Pokemon attacker)
        {
            double result = 1;

            if (attacker.HaveType(moveType))
            {
                if (attacker.GetSelTrait() == Trait.Adaptability)
                {
                    result *= 2;
                }
                else
                {
                    result *= 1.5;
                }
            }

            if (typeEffect < 1)
            {
                if (attacker.GetSelTrait() == Trait.TintedLens)
                    result *= 2;
            }
            else if (typeEffect > 1)
            {
                if (attacker.GetItem() == Item.ExpertBelt)
                    result *= 1.2;
            }

            return result;
        }

        public static double CalculateDefencerTypeRevision(double typeEffect, Pokemon defencer, bool moldBreak)
        {
            double result = 1;

            if (typeEffect > 1)
            {
                if (!moldBreak)
                {
                    if (defencer.GetSelTrait() == Trait.SolidRock)
                        result *= 3 / 4;
                    if (defencer.GetSelTrait() == Trait.Filter)
                        result *= 3 / 4;
                }
            }

            return result;
        }

        public static BattleType GetAttackMoveType(Move move, Pokemon attacker)
        {
            if (attacker.GetSelTrait() == Trait.Normalize)
                return BattleType.Normal;
            //if (attacker.BattleState.comboMoor)
            //{
            //    return BattleData.GetTypeData("草");
            //}
            //else if (attacker.BattleState.comboFlameSea)
            //{
            //    return BattleData.GetTypeData("火");
            //}
            //else if (attacker.BattleState.comboRainbow)
            //{
            //    return BattleData.GetTypeData("水");
            //}
            return move.Type;
        }

        /// <summary>
        /// 检测梦话
        /// </summary>
        private static bool CanSleepTalk(Move data)
        {
            //气合拳,喋喋不休
            int[] moveids = { 13, 19, 76, 91, 117, 119, 130, 143, 214, 253, 264, 291, 382, 383, 448, 467 };
            return data.PP > 0 && !moveids.Contains(data.Data.Id);
            //if (data.PP == 0) return false;
            //if ((MoveAdditionalEffect.准备后攻击 <= data.AddEff2 && data.AddEff2 <= MoveAdditionalEffect.消失后攻击) ||
            //    data.AddEff1 == MoveAdditionalEffect.次回合不能行动 ||
            //    data.AddEff2 == MoveAdditionalEffect.吵闹 ||
            //    data.AddEff2 == MoveAdditionalEffect.克制 ||
            //    data.Target == MoveTarget.技能 ||
            //    data.Effect == MoveEffect.先取 ||
            //    data.Effect == MoveEffect.模仿 ||
            //    data.Effect == MoveEffect.鹦鹉学舌 ||
            //    moveids.Contains(data.MoveId))
            //    return false;
            //return true;
        }

        /// <summary>
        /// 摇手指不能取到的技能
        /// </summary>
        private static bool CanCallMove(MoveData data)
        {
            int[] moveids = { 68, 102, 118, 119, 144, 165, 166, 168, 173, 182, 194, 197, 203, 214, 243, 264, 266, 267, 270, 271, 274, 289, 343, 364, 382, 383, 415, 448 };
            return !moveids.Contains(data.Id);
            //if (data.Target == MoveTarget.技能 ||
            //    data.Effect == MoveEffect.保护 ||
            //    data.Effect == MoveEffect.忍耐 ||
            //    data.Effect == MoveEffect.素描 ||
            //    data.Effect == MoveEffect.模仿 ||
            //    data.Effect == MoveEffect.抢夺 ||
            //    data.AddEffect2 == MoveAdditionalEffect.镜返 ||
            //    data.AddEffect2 == MoveAdditionalEffect.反击 ||
            //    data.Effect == MoveEffect.殊途同归 ||
            //    data.Effect == MoveEffect.帮手 ||
            //    data.Effect == MoveEffect.跟我来 ||
            //    data.AddEffect1 == MoveAdditionalEffect.夺取道具 ||
            //    data.Effect == MoveEffect.鹦鹉学舌 ||
            //    data.Effect == MoveEffect.戏法 ||
            //    data.Effect == MoveEffect.先取 ||
            //    moveids.Contains(data.Id))
            //    return false;
            //return true;
        }
    }
}
